{extend name="layouts/main" /}
{block name="css"}
<style>
	.layui-input-block{
		border: 1px solid #e6e6e6
	}
	.layui-input-block input{
		border: none;
	}
	.layui-input-block textarea{
		border: none;
	}
	.layui-input, .layui-select, .layui-textarea {
		height: 36px;
		line-height: 1.3;
		line-height: 36px\9;
	}
</style>
{/block}
{block name="content"}
<div class="layui-tab layui-tab-brief" lay-filter="demoTitle">
	<div class="layui-body layui-tab-content site-demo site-demo-body" style="top: 0px;left: 0px;">
		<div class="layui-tab-item layui-show">
			<div class="layui-main" style="width: auto;margin: 7px 15px;">
				<div id="LAY_preview">
					<div class="layui-fluid" style="position: relative;margin: 0 auto;padding: 0px;padding-top: 0px;">
						<div class="layui-card">
							<form class="layui-form" action="">
								<table class="layui-table" lay-filter="tableEvent">
									<colgroup>
										<col>
										<col>
									</colgroup>
									<thead>
										<tr>
											<th>节点名称</th>
											<th>操作</th>
										</tr>
									</thead>
									<tbody>
										<tr>
											<td>{$node_name}</td>
											<td>
												<div class="layui-inline">
													<div class="layui-input-inline" style="width: 300px;">
														<select name="category_id" lay-verify="required" class="upload-select">
															<option value="" selected="">选择栏目</option>
															{volist name="allArctypeRes" id="vo"}
															<option value="{$vo.id}"><?php if($vo['level']!==0){echo '|';} echo str_repeat('-',$vo['level']*5);?>{$vo.typename}</option>
															{/volist}
														</select>
														<span class="sysval"><em class="zerocopy">category_id</em></span>
													</div>
													<button class="layui-btn layui-btn-primary" type="button" id="export" onclick="exportdata();">导出数据</button>
												</div>
											</td>
										</tr>
										<tr>
											<td></td>
											<td>
												<div id="loading-1" style="text-align: left;padding:20px 0;display: none;">
													<img src="__STATIC__/common/images/loading-1.gif"><span>采集中......</span>
												</div>
												<div id="dg" style="text-align: left;padding:20px 0;display: none;">
													<img src="__STATIC__/addons/collection/images/dg.png"><span>采集完成</span>
												</div>

												<div id="export-data" style="text-align: left;padding:20px 0;display: none;">
													<img src="__STATIC__/common/images/loading-1.gif"><span>导出数据中......</span>
												</div>
												<div id="export-done" style="text-align: left;padding:20px 0;display: none;">
													<img src="__STATIC__/addons/collection/images/dg.png"><span>导出数据完成</span>
												</div>
												<button class="layui-btn layui-btn-normal" type="button" id="cjbtn" onclick="caiji();"><i class="menu-icon fa fa-bug"></i>开始采集</button>
											</td>
										</tr>
									</tbody>
								</table>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
{/block}
{block name="footer"}
{/block}
{block name="js"}
<script type="text/javascript">
	// 开始采集
	function caiji(s='1',curr='1'){
		// 当前节点id
        var node_id="{$node_id}";
        $.ajax({
        	type:"POST",
        	dataType:"json",
        	data:{node_id:node_id,s:s,curr:curr},
        	url:"{:url('do_caiji')}",
        	success:function(res){
        		if(res.code==2){
        			$("#cjbtn").removeClass("disabled");
        			$("#loading-1").hide();
        			$("#dg").show();
        		}else{
					caiji(res.s,res.curr);
				}
			},
			error:function(e){
				caiji(s,curr);
				// console.log(e);
				// var res = $.parseJSON(e.responseText);
				// console.log(res);
				// layer.msg('采集失败！', {icon: 2,time:1500}); 
				// return false;
			}
        });
        $("#dg").hide();
        $("#loading-1").show();
        // $("cjbtn").hide();
        $("#cjbtn").addClass("disabled");
    }
	// 导出采集数据到模型表
	function exportdata(){
		var category_id=$("select[name=category_id]").find("option:selected").val();
		if(category_id==''){
			layer.msg('请选择栏目！', {icon: 2,time:1500}); 
			return false;
		}
		// 当前节点id
		var node_id="{$node_id}";
		var ids = "{$ids}";
        $.ajax({
        	type:"POST",
        	dataType:"json",
        	data:{node_id:node_id,category_id:category_id,ids:ids},
        	url:"{:url('export_data')}",
        	success:function(res){
				if(res.code == 0){
					$("#export").removeClass("disabled");
        			$("#export-data").hide();
					$("#export-done").show();
					layer.msg(res.msg, {icon: 2,time:3000}); 
					return false;
				}else if(res.code==1){
					exportdata();
        		}else{
					$("#export").removeClass("disabled");
        			$("#export-data").hide();
        			$("#export-done").show();
				}
        	}
        });
        $("#dg").hide();
        $("#export-done").hide();
        $("#export-data").show();
        $("#export").addClass("disabled");
        $("#cjbtn").addClass("disabled");
    }
</script>
{/block}